package com.gong;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.DispatcherServlet;

import com.gong.common.IndexListener;
import com.gong.common.IndexServlet;

/**
 * Hello world!
 *
 */
@SpringBootApplication
//@ServletComponentScan
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        SpringApplication.run(App.class, args);
    }
    
    @Bean
    public ServletRegistrationBean indexServlet() {
    	ServletRegistrationBean servelets = new ServletRegistrationBean(new IndexServlet());
    	servelets.addUrlMappings("/index");
    	return servelets;
    }

    @Bean
    public ServletListenerRegistrationBean indexListener() {
    	ServletListenerRegistrationBean listenerRegistrationBean = new ServletListenerRegistrationBean<>(new IndexListener());
    	return listenerRegistrationBean;
    }
    
    @Bean
    public ServletRegistrationBean indexDispatcher(DispatcherServlet servlet) {
    	ServletRegistrationBean servelets = new ServletRegistrationBean(servlet);
    	
    	servelets.addUrlMappings("*.do");
    	servelets.addUrlMappings("*.json3");
    	
    	return servelets;
    }
}
